import {messages} from "share/common";
import React from 'react';
import {
  Card,
  Checkbox,
  Radio,
  Select
} from 'antd';

class FormItemAirlinePrice extends React.Component {
  constructor(props) {
    super(props);
    const value = props.value || {};
    this.state = {
      priceControl: {
        isPriceControl: value.isPriceControl || false,
        priceControlTime: value.priceControlTime || '1',
        priceControlReason: value.priceControlReason || []
      }
    };
  }
  componentWillReceiveProps(nextProps) {
    if (nextProps.value) {
      this.setState({ priceControl: nextProps.value });
    }
  }
  setControlReason = (values) => {
    this.triggerChange({
      priceControlReason: values
    });
  }
  changeTime = (value) => {
    this.triggerChange({
      priceControlTime: value
    });
  }
  switchControl = (e) => {
    this.triggerChange({
      isPriceControl: e.target.checked
    });
  }
  triggerChange = (changedValue) => {
    const { onChange } = this.props;
    if (onChange) {
      onChange(Object.assign({}, this.state.priceControl, changedValue));
    }
  }
  render = () => {
    const { priceControl } = this.state
    const { Option } = Select;
    return (<Card type="inner" title={messages('supplier.key273')/*机票预订最低价控制*/}>
      <Checkbox
        checked={priceControl.isPriceControl}
        onChange={this.switchControl}> {messages('supplier.key274')/*国内机票最低价控制*/}
      </Checkbox>
      {priceControl.isPriceControl && (
        <div>
          <div>{messages('supplier.key275')/*员工所选的航班需为预订时间前后给定时间段内最低价*/}
            <Select
              onChange={this.changeTime}
              defaultValue={'1'}
              value={priceControl.priceControlTime}
              style={{width: '150px', display: 'inline-block', margin: '0 6px'}}
            >
              <Option value={'1'}>1{messages('supplier.key276')/*小时*/}</Option>
              <Option value={'2'}>2{messages('supplier.key276')/*小时*/}</Option>
              <Option value={'4'}>4{messages('supplier.key276')/*小时*/}</Option>
            </Select>
          </div>
          <p>{messages('supplier.key277')/*若员工预订时未遵守以上要求，则系统会要求其从以下原因中选择其一，并统计在管理报表中*/}</p>
          <Checkbox.Group
            onChange={this.setControlReason}
            value={priceControl.priceControlReason}>
            <Checkbox value={'1'}>{messages('supplier.key278')/*陪同客户领导*/}</Checkbox>
            <Checkbox value={'2'}>{messages('supplier.key279')/*航空公司偏好*/}</Checkbox>
            <Checkbox value={'3'}>{messages('supplier.key280')/*机场选择*/}</Checkbox>
            <Checkbox value={'4'}>{messages('supplier.key281')/*退改签及行李额因素*/}</Checkbox>
            <Checkbox value={'5'}>{messages('supplier.key282')/*起飞或到达时间不合适*/}</Checkbox>
            <Checkbox value={'6'}>{messages('supplier.key283')/*余票不足*/}</Checkbox>
          </Checkbox.Group>
        </div>
      )}
    </Card>);
  }
}

export default FormItemAirlinePrice;
